#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   get_Freq.py
@Time    :   2021/12/01 10:54:33
@Author  :   glx 
@Version :   1.0
@Contact :   18095542g@connect.polyu.hk
@Desc    :   To get the origin position data and speed data of aircraft/ship/sat 

'''


__all__ = ["get_data", "read_data"]

# here put the import lib
import pandas as pd
import numpy as np
import matplotlib
# matplotlib.use('Agg')
import matplotlib.pyplot as plt
import os
import sys
import copy

def get_data(data_url = "data\out_put"):
    """获取csv文件的路径 """
    csv_list = [i for i in os.listdir(data_url) if i.endswith('.csv')]
    data_dict = {}
    # 根据不同文件生成pd的dataframe
    for i in csv_list:
        data_name = i.split(".")[0].split("_")
        data_type = copy.deepcopy(data_name[0])
        data_dict[data_type] = dict()

    for i in csv_list:
        data_name = i.split(".")[0].split("_")
        data_type = copy.deepcopy(data_name[0])
        target_type = copy.deepcopy(data_name[1])
        
        if data_type.startswith('F'): # 频率数据
            column = ["Freq"]
            data_dict[data_type][target_type] = copy.deepcopy(read_data(os.path.join(data_url,i), column))

        elif data_type.startswith('T'): # 轨迹数据
            column = ["pos_x", "pos_y", "pos_z", "vel_x", "vel_y", "vel_z"]
            data_dict[data_type][target_type] = copy.deepcopy(read_data(os.path.join(data_url,i), column))


        elif data_type.startswith("V"): # 速度数据
            column = ["v"]
            data_dict[data_type][target_type] = copy.deepcopy(read_data(os.path.join(data_url,i), column))

        elif data_type.startswith("A"):
            column = ["degree"]
            data_dict[data_type][target_type] = copy.deepcopy(read_data(os.path.join(data_url,i), column))
        
        else:
            print("Error: 文件名不符合规范")

    return data_dict

def read_data(data_url, column):
    """ 整理成pandas的dataframe格式 """
    data = pd.read_csv(data_url)
    data.columns = column
    return data
    
if __name__ == "__main__":
    output_data_folder = "data\out_put"
    data_dict = get_data(output_data_folder)
    data_dict["Freq"]["car"].tail(100000).plot()
    plt.show()
